#ifndef RELATION_H_
#define RELATION_H_

#include "ComponentDER.h"
#include "CompositeAttribute.h"
#include "Entity.h"
#include <vector>

typedef enum TypeOfRelation {
	TypeOfRelation0pp1 = 1,
	TypeOfRelation1pp1,
	TypeOfRelation0ppN,
	TypeOfRelation1ppN,
	TypeOfRelationNppN
} TypeOfRelation;

class EntityRelationLinkInfo {
public:
	Entity *entity;
	Connector *conectorDeLaEntidad;
	Connector *conectorDeLaRelacion;
	TypeOfRelation typeOfRelation;

	EntityRelationLinkInfo(Entity *entity, std::string viaType, Connector *conectorDeLaEntidad, Connector *conectorDeLaRelacion);
	std::string description();
};

//class EntityEntityLinkInfo {
//public:
//	Entity *entity1;
//	Entity *entity2;
//	Connector *conector1;
//	Connector *conector2;
//	TypeOfRelation typeOfRelation;
//
//	EntityEntityLinkInfo(Entity *entity1, Connector *conector1, Connector *conector2, Entity *entity2, std::string viaType);
//	std::string description();
//};

class Relation: public ComponentDER {
	std::vector<EntityRelationLinkInfo *> _relationLinkedEntities;
//	std::vector<EntityEntityLinkInfo *> _entitityEntityRelationLinks;
	std::vector<Attribute *> _relationAttributes;
	std::vector<CompositeAttribute *> _relationCompositeAttributes;

	virtual void initializeConnectors();
public:
	Relation(const std::string & name = TARGET_RELATION, int orientation = 0);

	Relation(const Relation &);
	Relation& operator=(const Relation&);

	virtual void serialize(XmlWriter & writer_rep, XmlWriter & writer_comp);

	virtual void update();

	bool tieneAtributos();

	std::vector<Attribute *> getRelationAttributes() {
		update();
		return _relationAttributes;
	}

	std::vector<CompositeAttribute *> getRelationCompositeAttributes() {
		update();
		return _relationCompositeAttributes;
	}

	std::vector<EntityRelationLinkInfo *> getLinkedEntities() {
		update();
		return _relationLinkedEntities;
	}

//	std::vector<EntityEntityLinkInfo *> getEntityEntityRelationLinks() {
//		update();
//		return _entitityEntityRelationLinks;
//	}

	virtual std::string description();
};

#endif /* RELATION_H_ */
